function SS=SteadyState_Solver(PP,FracHN_wN_0)
% clear;
% clc;
% PP          =   Setup_PP(struct());
%% Preliminaries
if PP.InfoPrint>3
    PrintFlag   =   1;
end
if nargin<=1
    PSI_0       =   1.2;
    FracHN_w_0  =   1;
    DiscFactor_0=   0.1;
    FracHN_wN_0 =   1;
end

%% Initiate the SS
if PrintFlag
    fprintf(['Start Solving the Steady State ...\n']);
end
TimeStart   =   tic;
SS          =   struct();
%--------------------------------------------------------------------------
% Exogenously Fixed
%   Note: 
%--------------------------------------------------------------------------
SS.Pir      =   PP.Pir_SS;
SS.Pir_N    =   SS.Pir;
SS.Pir_H    =   SS.Pir;
SS.Pir_F    =   SS.Pir;
SS.Pir_H_s  =   SS.Pir_H;
SS.Pir_F_s  =   SS.Pir_F;

SS.p_N      =   1;
SS.p_T      =   1;
SS.p_H      =   1;
SS.p_F      =   1;

SS.dE       =   SS.Pir_H-SS.Pir_H_s;

SS.N        =   PP.N_SS;              
SS.ir_dom   =   PP.i_dom_SS;
SS.ir_ext   =   PP.i_ext_SS;
SS.ir       =   SS.ir_dom;
SS.ir_s     =   SS.ir_ext;
SS.rr_dom   =   SS.ir-SS.Pir;
SS.rr_ext   =   SS.ir_s+SS.dE-SS.Pir;

SS.TAU      =   PP.TAU_SS;
SS.T        =   PP.T_SS;

SS.FracT_pC =   PP.Cons_FracT*(SS.p_T)^(1-PP.Cons_ElasTN);
SS.FracN_pC =   (1-PP.Cons_FracT)*(SS.p_N)^(1-PP.Cons_ElasTN);
SS.FracH_pC =   PP.Cons_FracH*(SS.p_H/SS.p_T)^(1-PP.Cons_ElasHF)*SS.FracT_pC;
SS.FracF_pC =   (1-PP.Cons_FracH)*(SS.p_F/SS.p_T)^(1-PP.Cons_ElasHF)*SS.FracT_pC;


%% Solve the SS by Finding to Equilibrium 
%--------------------------------------------------------------------------
% Solve the root by Newton Update 
%   Note: 
%       1. Save time by recycling the UCoef from the intermediate step.
%       2. Fastest, but might not be robust when Diff(PSI,ra) is too flat.
%--------------------------------------------------------------------------
Input_0     =   [FracHN_wN_0];
[SS,ExitFlag]=  SteadyState_Solver_Newton(PP,SS,Input_0);
%--------------------------------------------------------------------------
% Recollect the Steady State
%   Note: 
%--------------------------------------------------------------------------
TimeElapsed     =   toc(TimeStart);
if PrintFlag
    fprintf(['Steady State is Solved, Elapse Time=',num2str(TimeElapsed,'%.2f'),'s','\n',...
             'Equilibrium Residual: \n',...
             'N-Goods Market: ',num2str(SS.RES(1),'%.2e'),', \n',...
             'Final Good Market: ', num2str(SS.RES_FinalGood),'.\n']);
end


